package edu.scdx.controller;
import java.util.List;

import java.io.*;
import java.util.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import edu.scdx.common.util.JsonUtil;
import edu.scdx.entity.Goods;
import edu.scdx.entity.UserInfo;
import edu.scdx.service.GoodsService;
import edu.scdx.service.UserInfoService;
import edu.scdx.service.UserService;

@Controller
@RequestMapping("/goods")
public class GoodsController {
	
	 @Autowired
	 private GoodsService goodsService;

	public GoodsService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	 
	@RequestMapping("/seeGoods.do")
    public String getInfo(Model model,HttpSession session,int id){	
		
		Goods good=goodsService.getGoodById(id);
		
		session.setAttribute("id", id);
		
		model.addAttribute("good",good);
		
		return "seeGoodsInfo";
		
    }
	
	@RequestMapping("/getWenxue.do")
    public String getWenxue(Model model,HttpSession session){	
				
		String wenxue="文学小说";
		
		
		List<Goods> goods=goodsService.getAllWenxue(wenxue);		
		
		model.addAttribute("wenxue",goods);
		
		
		return "wenxue";
		
    }
	
	@RequestMapping("/getSheke.do")
    public String getSheke(Model model,HttpSession session){	
				
		String sheke="社科图书";
		
		List<Goods> goods=goodsService.getAllSheke(sheke);
		
		model.addAttribute("sheke",goods);
		
		return "sheke";
		
    }
	
	@RequestMapping("/getErtong.do")
    public String getErtong(Model model,HttpSession session){	
				
		String ertong="儿童图书";
		
		List<Goods> goods=goodsService.getAllErtong(ertong);
		
		model.addAttribute("ertong",goods);
		
		return "ertong";
		
    }
	
	@RequestMapping("/getJiaoxue.do")
    public String getJiaoxue(Model model,HttpSession session){	
				
		String jiaoxue="教学辅导";
		
		List<Goods> goods=goodsService.getAllJiaoxue(jiaoxue);
		
		model.addAttribute("jiaoxue",goods);
		
		return "jiaoxue";
		
    }
	
	
	@RequestMapping("/getGoodsByName.do")
    public String getGoodsByName(Model model,HttpSession session,String name){	
		
		List<Goods> goods=goodsService.getGoodsByName(name);
				
		model.addAttribute("search",goods);
		
		return "seeSearch";
		
    }
	
	@RequestMapping("/adminGoods.do")
    public String adminGoods(Model model,HttpSession session){	
		
		
		return "uploadGood";
		
    }
	
	@RequestMapping("/addGood.do")
    public String addGoods(Model model,HttpSession session,String name,String author,String type,
    		String publisher,Double price,String description,Double kou){	
		
		goodsService.addGoods(name,author,type,publisher,price,description,kou);
		
		
        
        

		
		
		return "addOk";
		
    }
	
	@RequestMapping("/shouye.do")
    public String addGoods(Model model,HttpSession session){	
		
		
		List<Goods> goods = goodsService.getAll();
		
		model.addAttribute("list",goods);
		
		
		return "welcome";
		
    }
	
	@RequestMapping("/lingling.do")
    public String lingling(Model model,HttpSession session){	
		

		return "lingling";
		
    }
	
	

}
